/**
 * 判断是否是火狐
 * @returns {boolean}
 */
export const isFirefox = function () {
  return !!window.navigator.userAgent.match(/firefox/i)
}

/**
 *
 * @param fn
 * @returns {Function}
 */
export function rafThrottle (fn) {
  let locked = false
  return function (...args) {
    if (locked) return
    locked = true
    window.requestAnimationFrame(_ => {
      fn.apply(this, args)
      locked = false
    })
  }
}

export const on = function (element, event, handler) {
  if (document.addEventListener) {
    if (element && event && handler) {
      element.addEventListener(event, handler, false)
    }
  } else {
    if (element && event && handler) {
      element.attachEvent('on' + event, handler)
    }
  }
}

export const off = function (element, event, handler) {
  if (document.removeEventListener) {
    if (element && event) {
      element.removeEventListener(event, handler, false)
    }
  } else {
    if (element && event) {
      element.detachEvent('on' + event, handler)
    }
  }
}
